package com.colin.app.fragment.recyclerview;

import android.support.v7.widget.RecyclerView;

import com.colin.app.app.AppActivity;
import com.colin.app.app.BasePresenterImpl;
import com.colin.app.bean.ItemBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Colin on 2017/1/15.
 */

public class RecyclerViewPresenterImpl extends BasePresenterImpl implements RecyclerViewContract.RecyclerViewPresenter {

    private RecyclerViewContract.RecyclerViewView mRecyclerViewView;
    private RecyclerViewContract.RecyclerViewModel mRecyclerViewModel;

    public RecyclerViewPresenterImpl(AppActivity mAppActivity, RecyclerViewContract.RecyclerViewView mRecyclerViewView, int fragment_id) {
        super(mAppActivity, mRecyclerViewView);
        this.mRecyclerViewView = mRecyclerViewView;
        this.mRecyclerViewModel = new RecyclerViewModelImpl(fragment_id);
    }

    @Override
    public List<ItemBean> getItemBeanList(boolean isRefresh) {
        int page = isRefresh ? 1 : mRecyclerViewModel.getPage();
        List<ItemBean> itemBeanList = new ArrayList<>();
        itemBeanList.addAll(mRecyclerViewModel.getItemBeanList(page));
        mRecyclerViewModel.setPage(page + 1);
        return itemBeanList;
    }

    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return mRecyclerViewModel.getLayoutManager(mAppActivity);
    }

    @Override
    public boolean isLastPage() {
        return mRecyclerViewModel.getPage() == 4;
    }
}
